$(function () {
	//修改组团
	$("#btn_premisesUpdate").on("click", function(){
		//var premisesId = $("input[name='premisesId']").val();
		//var parentName = $("input[name='parentName']").val();
		//singleUpdate(premisesId, parentName);
		var id = $("#premisesId").val();
		var url=jypath+"/estate/projectPremises/save_edit_lc?id="+id;
   		window.location.href = url;
	});
	
	//批量修改,修改内容为房源
	$("#btn_roomBatchUpdate").on("click", function(){
		var projectId=$("#projectId").val();
		var premisesId = $("input[name='premisesId']").val();
		var url=jypath+"/estate/projectRoom/toBatchUpdate?projectId="+projectId+"&premisesId="+premisesId;
		window.location.href=url;
	});
	
	//批量导入,跳转到导入界面
	$("#btn_toBatchImport").on("click", function(){
		var projectId = $("#projectId").val();
		var tabKey = "batchImp_" + projectId;
     	var url = "/estate/import/indexLC?id="+projectId+"&menu=";
       	parent.openMenu("0",tabKey,"","批量导入",url);
		
	});
	
	//删除组团
	$("#btn_premisesDel").on("click", function(){
		var premisesId = $("input[name='premisesId']").val();
		del(premisesId);
	});
	
});

//组团修改弹出层
function singleUpdate(premisesId, parentName){
	clearForm();
	console.log($("#testRemark").val());
	JY.Ajax.doRequest(null,jypath+'/estate/projectPremises/view',{id:premisesId},function(data){
		setPremisesForm(data);
		$("#premisesForm label[name='parentName']").text(parentName);
    	save("修改组团","/estate/projectPremises/edit", premisesId);
	});
}
function save(title, url, id){
	JY.Model.edit("premisesDiv",title,function(){
		if(JY.Validate.form("premisesForm")){
			var that =$(this);
			JY.Ajax.doRequest("premisesForm",jypath +url,null,function(data){	
				that.dialog("close");
	        	JY.Model.info(data.resMsg,function(){
	        		var url = jypath + "/estate/projectPremises/detail?id="+id;
	        		$.post(url, null, function(data){
	        			$("#rightContentDiv").html(data);
	        		});
        		});    
			 });
		}	
	});
}

function del(id){
	JY.Model.confirm("该操作将同步删除其下所有子孙节点的信息!&emsp;是否确认删除？",function(){	
		JY.Ajax.doRequest(null,jypath+'/estate/projectPremises/delete',{id:id},function(data){
			JY.Model.info(data.resMsg,function(){
				$("#rightContentDiv").html("");
 				if(data.res == 1){
 	 				deleteNode();
 	 			}
			});
		});
	});
}

function setPremisesForm(data){
	var obj = data.obj;
	$("#premisesForm input[name$='id']").val(JY.Object.notEmpty(obj.id));
	$("#premisesForm input[name$='groupName']").val(JY.Object.notEmpty(obj.groupName));
	$("#premisesForm input[name$='premisesCode']").val(JY.Object.notEmpty(obj.premisesCode));
	$("#premisesForm select[name$='deliveryFlag']").val(JY.Object.notEmpty(obj.deliveryFlag));
	$("#premisesForm input[name$='deliveryDateOrigin']").val(JY.Object.notEmpty(JY.Date.Format(obj.deliveryDate,"yyyy-MM-dd")));
	$("#premisesForm textarea[name$='remark']").val(JY.Object.notEmpty(obj.remark));
}

function setCarAreaForm(data){
	var obj = data.obj;
	$("#premisesForm input[name$='id']").val(JY.Object.notEmpty(obj.id));
	$("#premisesForm input[name$='groupName']").val(JY.Object.notEmpty(obj.groupName));
	$("#premisesForm input[name$='premisesCode']").val(JY.Object.notEmpty(obj.premisesCode));
	$("#premisesForm select[name$='deliveryFlag']").val(JY.Object.notEmpty(obj.deliveryFlag));
	$("#premisesForm input[name$='deliveryDateOrigin']").val(JY.Object.notEmpty(JY.Date.Format(obj.deliveryDate,"yyyy-MM-dd")));
	$("#premisesForm textarea[name$='remark']").val(JY.Object.notEmpty(obj.remark));
}

function clearForm(){
	JY.Tags.cleanForm("premisesForm");
	$("#premisesForm select[name$='deliveryFlag']").prop("value","1");//类别
}

